<?php
	function delete_all_childs($id,$tree) {
		unset($_SESSION["tree_session"][$id]);
			foreach ($tree as $key=>$item) {
				if ($item["parent"]["id"]>0 && $item["parent"]["id"]==$id) {
				delete_all_childs($item["id"],$tree);
			}
		}
	}

	function xajax_tree($id, $depth, $data_path) {
		global $smarty, $treeclass;
		
		$tree_types = $treeclass->gettreetypes('tree');
		$treeclass->maketree(0, $_SESSION['lang'], $tree_types);
		$tree = $treeclass->mas;
		
		if ($_SESSION["tree_session"][$id]) {
			delete_all_childs($id, $tree);
		} else {
			$_SESSION["tree_session"][$id] = 1;  
		}
		
		/*
		$tmp = $tree; 
		$tree = array();
		foreach ($tmp as $key=>$item) {
			if (isset($_SESSION["tree_session"][$id]) || ($item['parent'] == 0)) $tree[] = $item;
		}
		*/
		
		$smarty->assign("tree", $tree);
		$smarty->assign("selected", $id);
		$smarty->assign("depth", $depth);
		$smarty->assign("xxx", 1);
		$str = $smarty->fetch('admin/xajax-tree.html');	
		
		$objResponse = new xajaxResponse();
		$objResponse->addAssign("xajax_tree", "innerHTML", $str);
		return $objResponse;
	}
?>
